﻿using System;
using System.Collections.Generic;
using System.Linq;
using Game.Foundation;
using Bruce.Net;

namespace Server.Game.Generic
{
    public class GameAreaServer : GameAreaConfig
    {
        private List<GameRoomServer> _roomList;

        public GameAreaServer()
        {
            this._roomList = new List<GameRoomServer>();
        }

        public void RegisterRoom(GameRoomServer room)
        {
            if (room == null) return;

            this._roomList.Add(room);
        }

        public GameRoomServer GetRoom(int roomId)
        {
            return this._roomList.SingleOrDefault(r => r.ID == roomId);
        }

        public byte[] GetBytes()
        {
            byte[] data = BitConverter.GetBytes(this.ID);
            data = ArrayHelper.Join(data, BytesParser.StringToBytes(this.Name));
            data = ArrayHelper.Join(data, BitConverter.GetBytes(this._roomList.Count));
            foreach (GameRoomServer room in this._roomList)
            {
                data = ArrayHelper.Join(data, BitConverter.GetBytes(room.ID));
                data = ArrayHelper.Join(data, BytesParser.StringToBytes(room.Name));
                //data = ArrayHelper.Join(data, BitConverter.GetBytes(room.DeskCount));
            }

            return data;
        }
    }
}
